#ifndef STATE_H_INCLUDED
#define STATE_H_INCLUDED

#include "XGE_Common.h"
#include "Element.h"

namespace XGE
{
    class State : public XGE::Element, public Ogre::FrameListener
    {
        protected:
            Ogre::SceneManager* smScene;
            bool bPause;

        public:
            State(const Ogre::String& nName) : Element(nName)
            {
                smScene = 0;
                bPause = false;
            };

            virtual ~State()
            {
                if(smScene)
                {
                    Ogre::Root::getSingletonPtr()->destroySceneManager(smScene);
                }

                Ogre::Root::getSingletonPtr()->removeFrameListener(this);
            };

            //Called before createScene, load required resources, etc
            virtual void _onEnter(void) = 0;
            //Called before destroyScene, release required resources, etc
            virtual void _onExit(void) = 0;
            //Defines what should be created within the scene
            virtual bool _createScene(void) = 0;
            //Properly destroys the scene
            virtual bool _destroyScene(void) = 0;
            //Required by Ogre::FrameListener, called at the beginning of a frame
            virtual bool frameStarted(const Ogre::FrameEvent& evt) = 0;
            //Required by Ogre::FrameListener, called at the end of a frame
            virtual bool frameEnded(const Ogre::FrameEvent& evt) = 0;

            //Pause the state
            virtual void pause(const bool& toggle) { bPause = toggle; };
    };
}

#endif // STATE_H_INCLUDED
